#!/usr/bin/env node

var os = require('os');
var qrcode = require('./js/qrcode.js');

function getIPAdress() {
    var interfaces = os.networkInterfaces();
    for(var devName in interfaces){
        var iface = interfaces[devName];
        for(var i=0;i<iface.length;i++){
            var alias = iface[i];
            if(alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal){
                return alias.address;
            }
        }
    }
}

var args = process.argv.splice(2);
if (!args[0] || args[1]) {
    qrcode.resetScreen();
} else {
    qrcode.showCode(!/localhost/.test(args[0]) ? args[0]: args[0].replace('localhost', getIPAdress()));
}
